/***************************************************************************
 *   Copyright (C) 2008 by Rysiek Król,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "presentationwindow.h"

#include <QLabel>
#include <QGridLayout>
#include <QKeyEvent>
#include <QMouseEvent>

#include "displayoperations.h"
#include "picturemanager.h"
#include "filesoperations.h"

PresentationWindow::PresentationWindow ( QWidget *parent )
		: QDialog ( parent )
{

	QGridLayout *mainLayout = new QGridLayout;
	this->setLayout ( mainLayout );
	this->itsLabel = new QLabel();
	mainLayout->addWidget(this->itsLabel,1,1,Qt::AlignCenter);
	
	QPalette newPalette = palette();
        newPalette.setColor(QPalette::Active, QPalette::Window,Qt::black);
        newPalette.setColor(QPalette::Inactive, QPalette::Window,Qt::black);
        newPalette.setColor(QPalette::Disabled, QPalette::Window,Qt::black);
        newPalette.setColor(QPalette::Active, QPalette::Base,Qt::black);
        newPalette.setColor(QPalette::Inactive, QPalette::Base,Qt::black);
        newPalette.setColor(QPalette::Disabled, QPalette::Base,Qt::black);
	this->setPalette(newPalette);
	
	this->showFullScreen();
}


PresentationWindow::~PresentationWindow()
{
	delete this->itsLabel;
}

void PresentationWindow::setImage(QPixmap pixmap)
{
	this->itsLabel->setPixmap(pixmap);
}

void PresentationWindow::keyPressEvent(QKeyEvent * event)
{
		
               switch (event->key()) {
		case Qt::Key_Q :
                case Qt::Key_F :
		case Qt::Key_Escape :
			this->done(1);
                        ((PictureManager*)this->parent())->fullScreenSwichSlot();
                        break;
                case Qt::Key_Space :
                case Qt::Key_Return :
                case Qt::Key_Enter :
                        ((PictureManager*)this->parent())->getDisplayOperations()->displayNextImage();
                        break;
                case Qt::Key_Backspace:
                        ((PictureManager*)this->parent())->getDisplayOperations()->displayPreviousImage();
                        break;
                case Qt::Key_Delete :
                        ((PictureManager*)this->parent())->getFilesOperations()->deleteFilesSlot();
                        break;
                case Qt::Key_BracketRight:
                	((PictureManager*)this->parent())->getDisplayOperations()->rotateImage(90);
                break;
                case Qt::Key_BracketLeft:
                	((PictureManager*)this->parent())->getDisplayOperations()->rotateImage(270);
                break;
                }

}

/**
* Handles MousePressed Event
*/
void PresentationWindow::mousePressEvent(QMouseEvent * event)
{
       
                switch (event->button()) {
                case Qt::LeftButton:
                        ((PictureManager*)this->parent())->getDisplayOperations()->displayNextImage();
                        break;
                case Qt::RightButton:
                        ((PictureManager*)this->parent())->getDisplayOperations()->displayPreviousImage();
                        break;
                default:
                        break;
                }
        
}

/**
* Handles Wheel Event
*/
void PresentationWindow::wheelEvent(QWheelEvent * event)
{
        if ( ((PictureManager*)this->parent())->getIsPresentationMode()) {
                if (event->delta()>0 && event->delta()>15) {
                        ((PictureManager*)this->parent())->getDisplayOperations()->displayPreviousImage();
                } else if (event->delta()<0 && event->delta()<-15) {
                         ((PictureManager*)this->parent())->getDisplayOperations()->displayNextImage();
                }
        } else {
                event->ignore();
        }
}



